<template>
  <div id="sign" v-if="show">
    <div class="bg" @click="clear"></div>
    <div class="modal">
      <div class="modal-top">
        <div class="modal-title">{{ text }}</div>
        <div class="modal-clear" @click="clear">
          <img src="../assets/imgs/shanchu.png" alt />
        </div>
      </div>
      <div v-if="modal.length!=0" class="detailContent" v-loading="loading">
        <div class="tag">
          <div class="type">时间</div>
          <div class="type">收支信息</div>
          <div class="type">数量</div>
        </div>
        <div class="infor" v-for="(item, index) in modal" :key="index">
          <div class="date">{{ item.createTime }}</div>
          <div class="way">{{ item.changeType }}</div>
          <div class="num">{{ item.numType }}</div>
        </div>
      </div>
      <div class="paging" v-if="modal.length!=0">
        <el-pagination
          layout="prev, pager, next"
          :total="count"
          :page-size="8"
          :pager-count="7"
          @current-change="changePage"
        ></el-pagination>
      </div>
      <div class="infor noInfor" v-else>现在暂时没有信息哦~</div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    text: "",
  },
  data() {
    return {
      modal: [],
      show: false,
      res: "",
      totalPage: 0,
      count: 0,
      loading: true,
      name: "",
    };
  },

  mounted() {
    this.getRem(1920, 100);
  },
  watch: {
    text: {
      handler(newName, oldName) {
        if (newName == "荧光棒收支明细") {
          this.name = newName;
          console.log(this.name);
          this.init(`/account/frontend/sticklist`, 1);
        } else if (newName == "加速币收支明细") {
          this.name = newName;
          console.log(this.name);
          this.init(`/account/frontend/expendlist`, 1);
        }
      },
    },
  },
  methods: {
    init(url, page) {
      this.loading = true;
      this.$fetch(`/laiwen/${url}?page=${page}&limit=8`).then((res) => {
        this.loading = false;
        this.totalPage = res.totalPages;
        this.modal = res.list;
        this.res = res;
        this.count = res.count;
        for (let i of this.modal.keys()) {
          //处理正负显示
          let num = this.modal[i].number;
          let getNum = `+${this.modal[i].number}`;
          let giveNum = `-${this.modal[i].number}`;
          this.modal[i].transactionType == "支出"
            ? `${(num = giveNum)}`
            : `${(num = getNum)}`;
          this.$set(this.modal[i], "numType", num);
        }
        console.log(this.modal);
        if (this.modal.length == 0) {
          this.$set(this.res, "show", false);
        } else {
          this.$set(this.res, "show", true);
        }
      });
    },
    changePage(size) {
      if ((this.name = "荧光棒收支明细")) {
        this.init(`/account/frontend/sticklist`, size);
      } else {
        this.init(`/account/frontend/expendlist`, size);
      }
    },
    clear() {
      console.log(this.$props);
      this.show = !this.show;
    },
  },
};
</script>

<style scoped>
#sign {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  position: absolute;
  left: 0;
  top: 0;
}
.bg {
  width: 100%;
  height: 100%;
  opacity: 0.25;
  background: black;
  position: absolute;
}
.detailContent {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.modal {
  width: 5rem;
  height: 5.52rem;
  display: flex;
  align-items: center;
  position: relative;
  flex-direction: column;
  z-index: 9999;
  background: white;
  margin-top: 1.8rem;
  border-radius: 0.05rem;
}
.modal .modal-top {
  width: 100%;
  height: 0.64rem;
  display: flex;
  align-items: center;
  box-sizing: border-box;
  padding-left: 0.32rem;
  position: relative;
  border-bottom: 0.01rem solid #f5f5f5;
}
.modal .modal-top .modal-title {
  height: 0.2rem;
  font-size: 0.14rem;
  font-family: PingFang SC;
  font-weight: 400;
  line-height: 0.2rem;
  color: rgba(40, 40, 40, 1);
  opacity: 1;
}
.modal .modal-top .modal-clear {
  width: 0.11rem;
  height: 0.11rem;
  cursor: pointer;
  position: absolute;
  right: 0.32rem;
}

.clear {
  width: 1.22rem;
  height: 0.38rem;
  background: white;
  opacity: 1;
  border-radius: 0.05rem;
  cursor: pointer;
  font-size: 0.14rem;
  font-family: PingFang SC;
  font-weight: 400;
  line-height: 0.38rem;
  border: 0.01rem solid rgba(153, 153, 153, 1);
  text-align: center;
  color: #282828;
  opacity: 1;
}
.clear-btn {
  width: 0.24rem;
  height: 0.24rem;
  border-radius: 50%;
  opacity: 1;
  position: absolute;
  right: -0.24rem;
  top: 0.18rem;
  cursor: pointer;
}
.tag {
  width: 3.2rem;
  height: 0.22rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.16rem;
  font-family: PingFang SC;
  margin: 0.22rem 0rem;
}
.infor {
  width: 3.78rem;
  height: 0.2rem;
  margin-bottom: 0.22rem;
  display: flex;
  align-self: start;
  margin-left: 0.33rem;
  position: relative;
  align-items: center;
}
.date {
  width: 1.46rem;
  height: 0.2rem;
  font-size: 0.14rem;
  font-family: PingFang SC;
  font-weight: 400;
  line-height: 0.2rem;
  color: rgba(153, 153, 153, 1);
  text-align: center;
  opacity: 1;
}
.way {
  width: 0.64rem;
  height: 0.2rem;
  text-align: center;
  font-size: 0.14rem;
  font-family: PingFang SC;
  font-weight: 400;
  position: absolute;
  left: 1.85rem;
  line-height: 0.2rem;
  color: rgba(40, 40, 40, 1);
  opacity: 1;
}
.num {
  width: 0.34rem;
  height: 0.2rem;
  font-size: 0.14rem;
  font-family: PingFang SC;
  font-weight: 400;
  line-height: 0.2rem;
  color: rgba(255, 110, 4, 1);
  opacity: 1;
  align-self: flex-end;
  text-align: center;
  right: 0.02rem;
  position: absolute;
}
.paging {
  position: absolute;
  bottom: 0.32rem;
  margin-top: 0rem !important;
  margin-bottom: 0 !important;
}
.noInfor {
  display: flex;
  justify-content: center;
  align-items: center;
  color: #999999;
  font-size: 0.14rem;
  width: 3.48rem;
  height: 3.48rem;
  margin-left: 0.7rem;
}
</style>
